package com.sjf.day02.Search;

/**
 * 顺序查找
 *
 * @author <huangtang>
 * @since 2021/12/29 15:04
 **/
public class SeqSearch {

    public static void main(String[] args) {
        int[] arr = {3,75,66,99,108,523,347};
        int val = seqSearch(arr,523);
        if( val == -1){
            System.out.println("不存在要查找的值");
        }else{
            System.out.println("查找的值为："+val);
        }
    }

    /**
     * 顺序查找(找到一个满足的就返回)
     * @param arr 查找的数组
     * @param val 要查找的值
     * @return 返回查找的值，没有为-1
     */
    public static int seqSearch(int[] arr,int val){
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == val) return arr[i];
        }
        return -1;
    }

}
